<template>
  <div>
      <el-row>
          <el-col :span="24" align="right">
              <div style="margin-top:10px">
                <el-input style="width:200px" v-model="filters.name" placeholder="请输入事件名称"></el-input>
                <el-select v-model="filters.type" placeholder="请选择事件类型">
                  <el-option :value="1" label="一般事件"></el-option>
                  <el-option :value="2" label="重大事件"></el-option>
                </el-select>
                <!-- <el-select v-model="filters.status" placeholder="请输入事件处理状态">
                  <el-option v-for="(v,i) of EventStatus" :key="i" :label="v.sseventStatusTypeName" :value="v.sseventStatusTypeValue"></el-option>
                </el-select> -->
                <el-button type="primary" icon="search" @click="getInfo">搜索</el-button>
                <el-button type="primary" @click="flushAll">刷新</el-button>
              </div>
              <el-row style="margin-top:20px">
                  <el-col :span="$store.getters.user.userRole=='超级管理员'?3:0">
                      <treeComponent style="margin-top:-52px" @GetNodeValue="GetNodeValue"></treeComponent>
                  </el-col>
                  <el-col :span="$store.getters.user.userRole=='超级管理员'?21:24">
                      <el-table :data="list" border>
                          <el-table-column v-for="(v,k,i) in props" :key="v.id" :label="labels[i]" align="center">
                              <template scope="scope">
                                  <span v-if="k==='sex'">
                                       {{scope.row[k]==1?'男':'女'}}
                                  </span>
                                  <span v-else>
                                      {{scope.row[k]}}
                                  </span>
                              </template>
                          </el-table-column>
                          <el-table-column label="操作" width="200" align="center">
                              <template scope="scope">
                                  <el-button size="small" v-if="scope.row.spEventStatusTypeValue=='06'||scope.row.spEventStatusTypeValue=='08'" type="primary" @click="eventReview(scope.row.spEventID)">审核事件</el-button>
                                  <el-button type="text" @click="ckDetail(scope.row.spEventID)">查看详情</el-button>
                              </template>
                          </el-table-column>
                      </el-table>
                      <el-pagination style="margin-top:10px" layout="prev, pager, next" :total="totalInfo" @current-change="handleCurrentChange">
                      </el-pagination>
                  </el-col>
              </el-row>
          </el-col>
      </el-row>
      <el-dialog title="事件审核" :visible.sync="visible">
        <el-form :model="form" label-width="220px">
          <el-form-item  label="受理人" style="width:600px">
            <el-input disabled v-model="form.checkedUserID" placeholder=""></el-input>
          </el-form-item>
          <el-form-item label="审核时间">
            <el-date-picker  v-model="form.checkedTime" placeholder=""></el-date-picker>
          </el-form-item>
          <el-form-item label="审核结果">
              <el-radio-group v-model="form.checkedResult">
                <el-radio :label="1">通过</el-radio>
                <el-radio :label="0">不通过</el-radio>
              </el-radio-group>
          </el-form-item>
          <el-form-item label="备注" style="width:600px">
            <el-input type="textarea" v-model="form.remark" placeholder=""></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="success()">确认</el-button>
            <el-button type="warning" @click="visible = false">取消审核</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>

      <el-dialog top="5%" title="查看详情" :visible.sync="visible2">
      <info :id="id"></info>
    </el-dialog>
  </div>
</template>

<script>
import treeComponent from "../../components/common/treeComponent";
import * as api from "../../api/skynetManage";
import * as api2 from "../../api/securityManage";
import info from "./eventInfo";

export default {
  components: {
    treeComponent: treeComponent,
    info:info
  },
  data() {
    return {
      visible: false,
      visible2: false,
      id:'',
      filters: {
        id: 5,
        name: null,
        type: null,
        status: null,
        netGridID: null,
        page: 1,
        pageSize: 10
      },
      EventStatus: null,
      form: {
        skynetPatrolEventCheckedID: "", //,
        spEventID: "", //,
        checkedUserID: 5, //        bigint,
        checkedTime: "", //          datetime,
        checkedResult: "", //        int,
        remark: "" //              varchar(500),
      },
      list: [
        {
          spEventID: "", //bigint not null auto_increment,
          spEventName: "", //'事件名称',
          spEventKind: "", //'事件性质，如1=一般事件；2=重大事件；等',
          spEventTypeValue: "", //'事件类型，如杀人、放火、抢劫等',
          spEventContent: "",
          spEventStartDateTime: "",
          spEventEndDateTime: "",
          spEventHappenLongitude: "", //'地理经度信息',
          spEventHappenLatitude: "", //'地理纬度信息',
          spEventStatusTypeValue: "", //'当前事件处理的最新状态',
          currentRemarks: "",
          currentResponsiblePersonCertID: "", //'当前经办人员身份证号',
          currentResponsiblePersonName: "", //'当前经办人员姓名',
          currentResponsiblePersonContact: "", //'经办人员联系方式',
          netGridID: ""
        }
      ],
      totalInfo: 0,
      props: {
        spEventID: "", //bigint not null auto_increment,
        spEventName: "", //'事件名称',
        spEventTypeName: "", //'事件类型，如杀人、放火、抢劫等',
        spEventStatusTypeName: "",
        spEventStartDateTime:'',
        netGridName: ""
      },
      labels: ["编号", "事件名称", "事件类型", "当前事件处理状态","发生日期","所属网格"],
    };
  },
  methods: {
    success() {
      let type = this.form.checkedResult == 1 ? "07" : "08";
      api.insertSPEventChecked(this.form).then(res => {
        if (res.code == 200) {
          this.$message({
            type: "success",
            message: "审核信息上传成功!"
          });
          api.changeSPEventStatus(type, this.form.spEventID).then(res => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: "事件审核更新成功!"
              });
              this.getInfo();
              this.visible = false;
            } else {
              this.$message({
                type: "error",
                message: "事件审核更新失败!"
              });
            }
          });
        }
      });
    },
    eventReview(id) {
      this.form.spEventID = id;
      this.visible = true;
    },
    deleteEvent(id) {
      this.$confirm("是否删除此事件记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          api.deleteSPEvent(id).then(res => {
            if (res.data) {
              this.$message({
                type: "success",
                message: "删除成功!"
              });
              this.getInfo();
            } else {
              this.$message({
                type: "error",
                message: res.message
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    flushAll() {
      this.filters.name = this.filters.type = this.filters.status = null;
      this.getInfo();
    },
    handleCurrentChange(val) {
      this.filters.page = val;
      this.getInfo();
    },
    ckDetail(id) {
      this.id = id;
      this.visible2 = true;
    },
    addNewRecord() {
      this.$router.push("add");
    },
    GetNodeValue(val) {
      this.filters.netGridID = val;
      this.getInfo();
    },
    editEvent(id) {
      this.$router.push({ path: "editReview", query: { id: id } });
    },
    getInfo() {
      api.getSPEventAuditorQuery(this.filters).then(res => {
        this.list = res.data.list;
        this.totalInfo = res.data.page.totalCount;
      });
      this.filters.name = this.filters.type = this.filters.status = null;
    }
  },
  mounted() {
    this.filters.id = this.$store.getters.user.userID
    this.form.checkedUserID = this.$store.getters.user.userID
    if (this.$store.getters.user.userRole != "超级管理员")
      this.filters.netGridID = this.$store.getters.user.netGridID;
    this.getInfo();
    api2.getSSEventCode().then(res => {
      this.EventStatus = res.data.EventStatusType;
    });
  }
};
</script>


<style scoped>

</style>
